Public Class Form1 Inherits System.Windows.Forms.Form #Region " Windows Form Designer generated code " Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call End Sub 'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub 'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. Friend WithEvents Label1 As System.Windows.Forms.Label Friend WithEvents Label2 As System.Windows.Forms.Label Friend WithEvents TxtAccount As System.Windows.Forms.TextBox Friend WithEvents TxtPIN As System.Windows.Forms.TextBox Friend WithEvents Label3 As System.Windows.Forms.Label Friend WithEvents BtnSignIn As System.Windows.Forms.Button Friend WithEvents BtnQuit As System.Windows.Forms.Button Friend WithEvents GrpSignIn As System.Windows.Forms.GroupBox Friend WithEvents GrpTransaction As System.Windows.Forms.GroupBox Friend WithEvents TxtValidAcct As System.Windows.Forms.TextBox Friend WithEvents Label4 As System.Windows.Forms.Label Friend WithEvents TxtName As System.Windows.Forms.TextBox Friend WithEvents Label5 As System.Windows.Forms.Label Friend WithEvents BtnDeposit As System.Windows.Forms.Button Friend WithEvents BtnWithdraw As System.Windows.Forms.Button Friend WithEvents BtnInq As System.Windows.Forms.Button Friend WithEvents BtnQuit2 As System.Windows.Forms.Button Friend WithEvents TxtBal As System.Windows.Forms.TextBox Friend WithEvents BtnGo As System.Windows.Forms.Button Friend WithEvents txtAmount As System.Windows.Forms.TextBox Friend WithEvents GrpDetail As System.Windows.Forms.GroupBox Friend WithEvents LblAmount As System.Windows.Forms.Label Friend WithEvents BtnQuit3 As System.Windows.Forms.Button Friend WithEvents LblBalance As System.Windows.Forms.Label Private Sub InitializeComponent() Me.Label1 = New System.Windows.Forms.Label Me.GrpSignIn = New System.Windows.Forms.GroupBox Me.BtnQuit = New System.Windows.Forms.Button Me.BtnSignIn = New System.Windows.Forms.Button Me.TxtPIN = New System.Windows.Forms.TextBox Me.Label3 = New System.Windows.Forms.Label Me.TxtAccount = New System.Windows.Forms.TextBox Me.Label2 = New System.Windows.Forms.Label Me.GrpTransaction = New System.Windows.Forms.GroupBox Me.GrpDetail = New System.Windows.Forms.GroupBox Me.BtnQuit3 = New System.Windows.Forms.Button Me.TxtBal = New System.Windows.Forms.TextBox Me.LblBalance = New System.Windows.Forms.Label Me.txtAmount = New System.Windows.Forms.TextBox Me.LblAmount = New System.Windows.Forms.Label Me.BtnGo = New System.Windows.Forms.Button Me.BtnQuit2 = New System.Windows.Forms.Button Me.BtnInq = New System.Windows.Forms.Button Me.BtnWithdraw = New System.Windows.Forms.Button Me.BtnDeposit = New System.Windows.Forms.Button Me.TxtName = New System.Windows.Forms.TextBox Me.Label5 = New System.Windows.Forms.Label Me.TxtValidAcct = New System.Windows.Forms.TextBox Me.Label4 = New System.Windows.Forms.Label Me.GrpSignIn.SuspendLayout() Me.GrpTransaction.SuspendLayout() Me.GrpDetail.SuspendLayout() Me.SuspendLayout() ' 'Label1 ' Me.Label1.AutoSize = True Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 18.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label1.Location = New System.Drawing.Point(144, 16) Me.Label1.Name = "Label1" Me.Label1.Size = New System.Drawing.Size(253, 37) Me.Label1.TabIndex = 0 Me.Label1.Text = "Bank Of America" ' 'GrpSignIn ' Me.GrpSignIn.Controls.Add(Me.BtnQuit) Me.GrpSignIn.Controls.Add(Me.BtnSignIn) Me.GrpSignIn.Controls.Add(Me.TxtPIN) Me.GrpSignIn.Controls.Add(Me.Label3) Me.GrpSignIn.Controls.Add(Me.TxtAccount) Me.GrpSignIn.Controls.Add(Me.Label2) Me.GrpSignIn.Location = New System.Drawing.Point(24, 64) Me.GrpSignIn.Name = "GrpSignIn" Me.GrpSignIn.Size = New System.Drawing.Size(248, 168) Me.GrpSignIn.TabIndex = 1 Me.GrpSignIn.TabStop = False Me.GrpSignIn.Text = "Sign In" ' 'BtnQuit ' Me.BtnQuit.Location = New System.Drawing.Point(136, 120) Me.BtnQuit.Name = "BtnQuit" Me.BtnQuit.Size = New System.Drawing.Size(96, 32) Me.BtnQuit.TabIndex = 5 Me.BtnQuit.Text = "Quit" ' 'BtnSignIn ' Me.BtnSignIn.Location = New System.Drawing.Point(24, 120) Me.BtnSignIn.Name = "BtnSignIn" Me.BtnSignIn.Size = New System.Drawing.Size(96, 32) Me.BtnSignIn.TabIndex = 4 Me.BtnSignIn.Text = "Sign In" ' 'TxtPIN ' Me.TxtPIN.Location = New System.Drawing.Point(112, 80) Me.TxtPIN.Name = "TxtPIN" Me.TxtPIN.Size = New System.Drawing.Size(128, 22) Me.TxtPIN.TabIndex = 3 Me.TxtPIN.Text = "" ' 'Label3 ' Me.Label3.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.2!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label3.Location = New System.Drawing.Point(16, 80) Me.Label3.Name = "Label3" Me.Label3.Size = New System.Drawing.Size(112, 32) Me.Label3.TabIndex = 2 Me.Label3.Text = "PIN:" ' 'TxtAccount ' Me.TxtAccount.Location = New System.Drawing.Point(112, 40) Me.TxtAccount.Name = "TxtAccount" Me.TxtAccount.Size = New System.Drawing.Size(128, 22) Me.TxtAccount.TabIndex = 1 Me.TxtAccount.Text = "" ' 'Label2 ' Me.Label2.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.2!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label2.Location = New System.Drawing.Point(16, 40) Me.Label2.Name = "Label2" Me.Label2.Size = New System.Drawing.Size(112, 32) Me.Label2.TabIndex = 0 Me.Label2.Text = "Account:" ' 'GrpTransaction ' Me.GrpTransaction.Controls.Add(Me.GrpDetail) Me.GrpTransaction.Controls.Add(Me.BtnQuit2) Me.GrpTransaction.Controls.Add(Me.BtnInq) Me.GrpTransaction.Controls.Add(Me.BtnWithdraw) Me.GrpTransaction.Controls.Add(Me.BtnDeposit) Me.GrpTransaction.Controls.Add(Me.TxtName) Me.GrpTransaction.Controls.Add(Me.Label5) Me.GrpTransaction.Controls.Add(Me.TxtValidAcct) Me.GrpTransaction.Controls.Add(Me.Label4) Me.GrpTransaction.Location = New System.Drawing.Point(24, 248) Me.GrpTransaction.Name = "GrpTransaction" Me.GrpTransaction.Size = New System.Drawing.Size(432, 288) Me.GrpTransaction.TabIndex = 2 Me.GrpTransaction.TabStop = False Me.GrpTransaction.Text = "Banking Transactions" Me.GrpTransaction.Visible = False ' 'GrpDetail ' Me.GrpDetail.Controls.Add(Me.BtnQuit3) Me.GrpDetail.Controls.Add(Me.TxtBal) Me.GrpDetail.Controls.Add(Me.LblBalance) Me.GrpDetail.Controls.Add(Me.txtAmount) Me.GrpDetail.Controls.Add(Me.LblAmount) Me.GrpDetail.Controls.Add(Me.BtnGo) Me.GrpDetail.Location = New System.Drawing.Point(16, 168) Me.GrpDetail.Name = "GrpDetail" Me.GrpDetail.Size = New System.Drawing.Size(408, 112) Me.GrpDetail.TabIndex = 15 Me.GrpDetail.TabStop = False Me.GrpDetail.Text = "Transaction Details" Me.GrpDetail.Visible = False ' 'BtnQuit3 ' Me.BtnQuit3.Location = New System.Drawing.Point(320, 24) Me.BtnQuit3.Name = "BtnQuit3" Me.BtnQuit3.Size = New System.Drawing.Size(80, 32) Me.BtnQuit3.TabIndex = 19 Me.BtnQuit3.Text = "Quit" ' 'TxtBal ' Me.TxtBal.Location = New System.Drawing.Point(112, 72) Me.TxtBal.Name = "TxtBal" Me.TxtBal.ReadOnly = True Me.TxtBal.Size = New System.Drawing.Size(128, 22) Me.TxtBal.TabIndex = 18 Me.TxtBal.Text = "" ' 'LblBalance ' Me.LblBalance.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.2!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.LblBalance.Location = New System.Drawing.Point(16, 72) Me.LblBalance.Name = "LblBalance" Me.LblBalance.Size = New System.Drawing.Size(112, 32) Me.LblBalance.TabIndex = 17 Me.LblBalance.Text = "Balance:" ' 'txtAmount ' Me.txtAmount.Location = New System.Drawing.Point(112, 24) Me.txtAmount.Name = "txtAmount" Me.txtAmount.Size = New System.Drawing.Size(128, 22) Me.txtAmount.TabIndex = 15 Me.txtAmount.Text = "" ' 'LblAmount ' Me.LblAmount.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.2!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.LblAmount.Location = New System.Drawing.Point(16, 24) Me.LblAmount.Name = "LblAmount" Me.LblAmount.Size = New System.Drawing.Size(112, 32) Me.LblAmount.TabIndex = 14 Me.LblAmount.Text = "Amount:" ' 'BtnGo ' Me.BtnGo.Location = New System.Drawing.Point(256, 24) Me.BtnGo.Name = "BtnGo" Me.BtnGo.Size = New System.Drawing.Size(40, 32) Me.BtnGo.TabIndex = 16 Me.BtnGo.Text = "Go" ' 'BtnQuit2 ' Me.BtnQuit2.Location = New System.Drawing.Point(344, 120) Me.BtnQuit2.Name = "BtnQuit2" Me.BtnQuit2.Size = New System.Drawing.Size(80, 32) Me.BtnQuit2.TabIndex = 14 Me.BtnQuit2.Text = "Quit" ' 'BtnInq ' Me.BtnInq.Location = New System.Drawing.Point(224, 120) Me.BtnInq.Name = "BtnInq" Me.BtnInq.Size = New System.Drawing.Size(104, 32) Me.BtnInq.TabIndex = 8 Me.BtnInq.Text = "Check Balance" ' 'BtnWithdraw ' Me.BtnWithdraw.Location = New System.Drawing.Point(120, 120) Me.BtnWithdraw.Name = "BtnWithdraw" Me.BtnWithdraw.Size = New System.Drawing.Size(80, 32) Me.BtnWithdraw.TabIndex = 7 Me.BtnWithdraw.Text = "Withdraw" ' 'BtnDeposit ' Me.BtnDeposit.Location = New System.Drawing.Point(16, 120) Me.BtnDeposit.Name = "BtnDeposit" Me.BtnDeposit.Size = New System.Drawing.Size(80, 32) Me.BtnDeposit.TabIndex = 6 Me.BtnDeposit.Text = "Deposit" ' 'TxtName ' Me.TxtName.Location = New System.Drawing.Point(120, 72) Me.TxtName.Name = "TxtName" Me.TxtName.ReadOnly = True Me.TxtName.Size = New System.Drawing.Size(128, 22) Me.TxtName.TabIndex = 5 Me.TxtName.Text = "" ' 'Label5 ' Me.Label5.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.2!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label5.Location = New System.Drawing.Point(24, 72) Me.Label5.Name = "Label5" Me.Label5.Size = New System.Drawing.Size(112, 32) Me.Label5.TabIndex = 4 Me.Label5.Text = "Name:" ' 'TxtValidAcct ' Me.TxtValidAcct.Location = New System.Drawing.Point(120, 32) Me.TxtValidAcct.Name = "TxtValidAcct" Me.TxtValidAcct.ReadOnly = True Me.TxtValidAcct.Size = New System.Drawing.Size(128, 22) Me.TxtValidAcct.TabIndex = 3 Me.TxtValidAcct.Text = "" ' 'Label4 ' Me.Label4.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.2!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label4.Location = New System.Drawing.Point(24, 32) Me.Label4.Name = "Label4" Me.Label4.Size = New System.Drawing.Size(112, 32) Me.Label4.TabIndex = 2 Me.Label4.Text = "Account:" ' 'Form1 ' Me.AutoScaleBaseSize = New System.Drawing.Size(6, 15) Me.ClientSize = New System.Drawing.Size(488, 560) Me.Controls.Add(Me.GrpTransaction) Me.Controls.Add(Me.GrpSignIn) Me.Controls.Add(Me.Label1) Me.Name = "Form1" Me.Text = "Form1" Me.GrpSignIn.ResumeLayout(False) Me.GrpTransaction.ResumeLayout(False) Me.GrpDetail.ResumeLayout(False) Me.ResumeLayout(False) End Sub #End Region Const maxNumAccts As Integer = 200 Dim allAccounts(maxNumAccts) As account Dim actualNumAccts As Integer Dim currIndex As Integer Dim doingDeposit As Boolean = False Dim doingWithdraw As Boolean = False ' initialize a single account based on a line read from a file Private Sub getAcct(ByRef curr As account, ByVal line As String) Dim commapos As Integer ' get account id commapos = line.IndexOf(",") curr.acctNum = line.Substring(0, commapos) line = line.Substring(commapos + 1) ' get account name commapos = line.IndexOf(",") curr.custName = line.Substring(0, commapos) line = line.Substring(commapos + 1) 'get pin commapos = line.IndexOf(",") curr.PIN = line.Substring(0, commapos) line = line.Substring(commapos + 1) ' get balance If IsNumeric(line) Then curr.bal = Convert.ToDouble(line) Else MsgBox("Initial Account List has an error - Please call tech support") End If End Sub ' reads file of accounts - returning true if everything ok, otherwise false. ' Fills passed array ' num is updated with the number of real accounts found Private Function readAccounts(ByRef acct() As account, ByRef num As Integer, ByVal inputFilename As String) As Boolean Dim inAccts As IO.StreamReader Dim currLine As String Dim temp As account num = 0 If IO.File.Exists(inputFilename) Then ' file exists - open it inAccts = IO.File.OpenText(inputFilename) Do While inAccts.Peek <> -1 AndAlso num <= maxNumAccts ' pull out voter info from file ' first creat a temporary account to fill temp = New account ' read line of text from input file currLine = inAccts.ReadLine() ' fill the temporary account getAcct(temp, currLine) ' stick it in the array acct(num) = temp num = num + 1 Loop Return True Else MsgBox("Accounts List is Missing, Please Notify Authorities") Return False End If End Function ' find a account based on acctnum ' return -1 if not found, ' otherwise return location found Private Function findAccount(ByVal acct() As account, ByVal max As Integer, ByVal toFind As String) As Integer Dim cnt As Integer Dim found As Integer = -1 For cnt = 0 To actualNumAccts - 1 If acct(cnt).acctNum = toFind Then ' we found them found = cnt End If Next cnt Return found End Function Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim acctsOk As Boolean acctsOk = readAccounts(allAccounts, actualNumAccts, "accounts.txt") If acctsOk Then MsgBox("Welcome to Bank of America's Worldwide ATM Adventure") Else MsgBox("ATM out of service, please go home") End If End Sub Private Sub BtnSignIn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSignIn.Click Dim id As String id = TxtAccount.Text Dim acctIndex As Integer acctIndex = findAccount(allAccounts, actualNumAccts, id) ' check if they are found If acctIndex >= 0 Then ' found ' now need to see if the pin was correct If allAccounts(acctIndex).PIN = TxtPIN.Text Then ' correct ' they're good to work with their account ' pull their name into account name text box GrpTransaction.Visible = True ' not yet ready for details GrpDetail.Visible = False TxtName.Text = allAccounts(acctIndex).custName TxtValidAcct.Text = TxtAccount.Text ' remove them from the id and pasword so next person is ready to go TxtAccount.Text = "" TxtPIN.Text = "" ' make sure customer info is available for other buttons currIndex = acctIndex Else MsgBox("PIN is incorrect, go away you theif") ' currIndex = -1 ' not found End If Else MsgBox("Account number is not correct, please enter carefully") ' currIndex = -1 ' not found End If End Sub Private Sub BtnQuit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnQuit.Click Me.Close() End Sub Private Sub BtnQuit2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnQuit2.Click GrpTransaction.Visible = False currIndex = -1 End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnQuit3.Click GrpDetail.Visible = False End Sub Private Sub BtnInq_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnInq.Click ' make group box show, but hide things that aren't needed GrpDetail.Visible = True txtAmount.Visible = False BtnGo.Visible = False LblAmount.Visible = False BtnQuit3.Visible = False ' pull balance out of correct location in array TxtBal.Text = allAccounts(currIndex).acctInq().ToString("c") LblBalance.Visible = True TxtBal.Visible = True doingDeposit = False doingWithdraw = False End Sub Private Sub BtnDeposit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnDeposit.Click ' make group box show, but and ensure that other things that are needed show too GrpDetail.Visible = True txtAmount.Visible = True txtAmount.Text = "" txtAmount.Select() BtnGo.Visible = True LblAmount.Visible = True BtnQuit3.Visible = True LblBalance.Visible = False ' don't show until after trans TxtBal.Visible = False doingDeposit = True doingWithdraw = False End Sub Private Sub BtnWithdraw_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnWithdraw.Click ' make group box show, but and ensure that other things that are needed show too GrpDetail.Visible = True txtAmount.Visible = True txtAmount.Text = "" txtAmount.Select() BtnGo.Visible = True LblAmount.Visible = True BtnQuit3.Visible = True LblBalance.Visible = False ' don't show until after trans TxtBal.Visible = False doingDeposit = False doingWithdraw = True End Sub Private Sub BtnGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnGo.Click Dim ok As Boolean If IsNumeric(txtAmount.Text) Then Dim amt As Double = Convert.ToDouble(txtAmount.Text) If doingDeposit Then ok = allAccounts(currIndex).deposit(amt) If Not ok Then MsgBox("please enter positive amount") End If Else ' must be doing a withdraw ok = allAccounts(currIndex).withdraw(amt) If Not ok Then If amt <= 0 Then MsgBox("please enter positive amount") Else ' must not have enough money MsgBox("I'm sorry, you don't have that much money") End If End If End If If ok Then ' either deposit or withdrawal, adjust what is displayed LblBalance.Visible = True ' don't show until after trans TxtBal.Visible = True BtnGo.Visible = False ' display balance TxtBal.Text = allAccounts(currIndex).acctInq().ToString("c") End If End If End Sub End Class